package com.sayyi.controller;

import com.sayyi.proto.HeartBeatClass;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/protobuf")
public class ProtobufController {

    /**
     * 获取protobuf数据
     * @return
     */
    @GetMapping(value = "/", produces="application/x-protobuf;charset=UTF-8")
    public HeartBeatClass.HeartBeat get() {
        return HeartBeatClass.HeartBeat.newBuilder()
                .setIds(1)
                .setHeart(100)
                .setTime(200)
                .setRequestInfo(400)
                .build();
    }

    /**
     * 接收protobuf数据
      * @param heartBeat
     * @return
     */
    @PostMapping(value = "/", produces="application/x-protobuf;charset=UTF-8")
    public String post(@RequestBody HeartBeatClass.HeartBeat heartBeat) {
        return heartBeat.toString();
    }
}
